# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-optparse
_pkgname=optparse
pkgver=1.5
pkgrel=0
pkgdesc="Parse and process command-line options"
url="https://github.com/gvvaughan/optparse"
arch="noarch"
license="MIT"
source="$pkgname-$pkgver.tar.gz::https://github.com/gvvaughan/$_pkgname/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
options="!check"  # tests requires additional dependencies

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local lmod_dir="$subpkgdir/usr/share/lua/$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$pkgver-1"

	cd "$builddir"
	mkdir -p "$lmod_dir"
	cp -r "$builddir"/lib/* "$lmod_dir"/

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="
4bbf1cbd3006f2f0022d1fd5b0feed6e6b0db05e28692fd1f0ceb1b94cca3bd1f8fb9c1516e5a998f74a64231951332de491648e58771cf2f693059862d67f0e  lua-optparse-1.5.tar.gz
"
